{include file="public/header" /}

<div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 15px;">
        <h1>添加员工</h1>
        <form id="addForm" class="layui-form" method="post" action="<?= url('doadd')?>">
            <div class="layui-form-item">
                <label class="layui-form-label">姓名</label>
                <input class="layui-input layui-input-inline" type="text" name="Ename">
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">年龄</label>
                <input class="layui-input layui-input-inline" type="text" name="Eage">
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">部门</label>
                <div class="layui-input-inline">
                    <select name="Edeptno">
                        <?php if (isset($depts)): foreach ($depts as $item): ?>
                            <option value="<?= $item['Dno'] ?>"><?= $item['Dname'] ?></option>
                        <?php endforeach; endif; ?>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">头像</label>
                <div class="layui-input-inline">
                    <button type="button" class="layui-btn" id="btn_upload">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                    <input class="layui-input layui-input-inline" type="hidden" name="icon" id="icon">
                    <div id="show_img"></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">简介</label>
                <div class="layui-input-block">
                    <div id="desc">
                        <p>欢迎使用 <b>wangEditor</b> 富文本编辑器</p>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <input onclick="window.history.back();" class="layui-btn layui-btn-primary" type="button" value="返回">
                <input class="layui-btn" type="button" onclick="addEmp()" value="添加">
            </div>
        </form>
    </div>
</div>

<div class="layui-footer">
    <!-- 底部固定区域 -->
    © layui.com - 底部固定区域
</div>
</div>
<script src="__STATIC__/layui/layui.js"></script>
<script src="__STATIC__/js/jquery-1.12.4.min.js"></script>
<script src="//unpkg.com/wangeditor/release/wangEditor.min.js"></script>
<script>
    //JavaScript代码区域
    layui.use(['element', 'form', 'upload'], function(){
        var element = layui.element;

        //头像上传
        var upload = layui.upload;
        var uploadInst = upload.render({
            elem: '#btn_upload' //绑定元素
            ,url: "{:url('Upload/upload_pri')}" //上传接口,
            ,done: function(res){
                //上传完毕回调
                $('#icon').attr('value', res.data.name)
                $('#show_img').html("<img style='width: 100px;height: 100px;margin-top: 10px' src='" + res.data.path +"'>")
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });

    var E = window.wangEditor
    var editor = new E('#desc')

    editor.customConfig.uploadImgServer = "{:url('Upload/upload')}"  // 上传图片到服务器
    editor.customConfig.uploadFileName = 'image'

    editor.create()

    function addEmp() {
        var addForm = $('#addForm')
        $descInput = $("<input type='text' name='desc'>")
        $descInput.attr('value', editor.txt.html());
        addForm.append($descInput)
        addForm.submit()
    }

</script>
</body>
</html>
